# list depends here.
add_subdirectory(dfhooks)
install(TARGETS dfhooks LIBRARY DESTINATION . RUNTIME DESTINATION .)

add_subdirectory(lodepng)
add_subdirectory(lua)
add_subdirectory(md5)
add_subdirectory(protobuf)
target_include_directories(protobuf-lite INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/protobuf)

if(UNIX)
    set_target_properties(lua PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-deprecated-enum-enum-conversion")
    set_target_properties(protoc PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict")
    set_target_properties(protoc-bin PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict")
    set_target_properties(protobuf-lite PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict")
    set_target_properties(protobuf PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict")
endif()

option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" OFF)
add_subdirectory(googletest)

# Don't build tinyxml if it's being externally linked against.
if(NOT TinyXML_FOUND)
    add_subdirectory(tinyxml)
    target_include_directories(dfhack-tinyxml INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tinyxml)
endif()

option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" OFF)
option(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" OFF)
option(JSONCPP_BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF)
option(JSONCPP_BUILD_OBJECT_LIBS "Build jsoncpp_lib as a object library." OFF)
option(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF)

add_subdirectory(jsoncpp-sub EXCLUDE_FROM_ALL)
# build clsocket static and only as a dependency. Setting those options here overrides its own default settings.
option(CLSOCKET_SHARED "Build clsocket lib as shared." OFF)
option(CLSOCKET_DEP_ONLY "Build for use inside other CMake projects as dependency." ON)
add_subdirectory(clsocket)
ide_folder(clsocket "Depends")

# set the default values of libexpat options - the descriptions are left empty
# because later option() calls *do* override those
set(EXPAT_BUILD_EXAMPLES OFF CACHE BOOL "")
set(EXPAT_BUILD_TESTS OFF CACHE BOOL "")
set(EXPAT_BUILD_TOOLS OFF CACHE BOOL "")
set(EXPAT_SHARED_LIBS OFF CACHE BOOL "")
set(EXPAT_BUILD_DOCS OFF CACHE BOOL "")
set(EXPAT_ENABLE_INSTALL OFF CACHE BOOL "")
add_subdirectory(libexpat/expat)
if(UNIX)
    set_target_properties(expat PROPERTIES COMPILE_FLAGS "-Wno-maybe-uninitialized")
endif()

set(CMAKE_REQUIRED_QUIET ON)
set(LIBZIP_BUILD_DOC OFF CACHE BOOL "")
set(LIBZIP_BUILD_EXAMPLES OFF CACHE BOOL "")
set(LIBZIP_BUILD_REGRESS OFF CACHE BOOL "")
set(LIBZIP_BUILD_SHARED_LIBS OFF CACHE BOOL "")
set(LIBZIP_BUILD_OSSFUZZ OFF CACHE BOOL "")
set(LIBZIP_BUILD_TOOLS OFF CACHE BOOL "")
set(LIBZIP_ENABLE_BZIP2 OFF CACHE BOOL "")
set(LIBZIP_ENABLE_COMMONCRYPTO OFF CACHE BOOL "")
set(LIBZIP_ENABLE_GNUTLS OFF CACHE BOOL "")
set(LIBZIP_ENABLE_LZMA OFF CACHE BOOL "")
set(LIBZIP_ENABLE_MBEDTLS OFF CACHE BOOL "")
set(LIBZIP_ENABLE_OPENSSL OFF CACHE BOOL "")
set(LIBZIP_ENABLE_WINDOWS_CRYPTO OFF CACHE BOOL "")
set(LIBZIP_DO_INSTALL OFF CACHE BOOL "")
add_subdirectory(libzip)
if(MSVC)
    target_compile_options(zip PRIVATE /wd4244)
elseif(UNIX)
    set_target_properties(zip PROPERTIES COMPILE_FLAGS "-Wno-stringop-truncation -Wno-stringop-overflow")
endif()

set(XLSXIO_USE_DFHACK_LIBS ON CACHE BOOL "")
set(XLSXIO_BUILD_STATIC ON CACHE BOOL "")
set(XLSXIO_BUILD_SHARED OFF CACHE BOOL "")
set(XLSXIO_BUILD_DOCUMENTATION OFF CACHE BOOL "")
set(XLSXIO_BUILD_EXAMPLES OFF CACHE BOOL "")
set(XLSXIO_BUILD_TOOLS OFF CACHE BOOL "")
set(XLSXIO_WITH_LIBZIP ON CACHE BOOL "")
set(XLSXIO_ZLIB_DIR "${ZLIB_DIR}" CACHE PATH "")
set(XLSXIO_LIBZIP_DIR "${CMAKE_CURRENT_BINARY_DIR}/libzip" CACHE PATH "")
set(XLSXIO_EXPAT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libexpat" CACHE PATH "")
set(XLSXIO_ENABLE_INSTALL OFF CACHE BOOL "")
add_subdirectory(xlsxio)
if(MSVC)
    target_compile_options(xlsxio_read_STATIC PRIVATE /wd4013 /wd4244)
    target_compile_options(xlsxio_write_STATIC PRIVATE /wd4013 /wd4244)
endif()
target_include_directories(xlsxio_read_STATIC INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/xlsxio/include)
target_include_directories(xlsxio_write_STATIC INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/xlsxio/include)
